﻿@{
    ViewBag.Title = Model.Heading;
	Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
    bool hasSchema = Model.SchemaId >= 0;
}

@model DirigoEdge.Areas.Admin.Models.ViewModels.ManageContentViewModel

<div class="manageContent">

    <div class="row">
        <div class="twelve columns">
            <h3><i class="fa fa-file-text-o"></i> @Model.Heading</h3>
            
            @{
                string newButtonUrl = Url.Action("NewContentPage", "Admin");
                // If a schema is assigned, pass the variable along
                if (hasSchema)
                {
                    newButtonUrl = Url.Action("NewContentPage", "Admin", new { schemaId = Model.SchemaId, editContentHeading = Model.EditContentHeading });
                }
            }

            <a id="NewContentPage" class="button mobileMarginBottom mobileBlockStatic" href="@newButtonUrl">@Model.NewButtonText</a>

            <table class="manageTable twelve bordered manageTable">
                <thead>
                    <tr>
                        <th>Title</th>
                        <th class="hide-for-small">Created</th>
                        <th class="hide-for-small">Status</th>
                        <th class="actions">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @{
					    foreach(var page in Model.Pages)
					    {
                            string codeEditUrl;
					        if (hasSchema)
					        {
                                codeEditUrl = Url.Action("EditContent", "Admin", new { id = page.ContentPageId, schema = Model.SchemaId, editContentHeading = Model.EditContentHeading });
					        }
					        else
					        {
					            codeEditUrl = Url.Action("EditContent", "Admin", new {id = page.ContentPageId});
					        }

					        <tr>
                                <td class="title"><a href="@codeEditUrl">@page.Title</a></td>
                                <td class="hide-for-small">@Convert.ToDateTime(page.CreateDate).ToString("MM/dd/yyyy")</td>
                                
                                @{
                                    string published = Convert.ToBoolean(page.IsActive) ? "Published" : "Draft";
                                }

                                <td class="hide-for-small">@published</td>

                                <td>
                                    <a class="delete button secondary small tabletMarginBottom" href="javascript:void(0);" data-id="@page.ContentPageId">Delete</a>
                                    @{
                                            string url = "/" + page.Permalink + "/";
                                    }
                                    <a class="button secondary small tabletMarginBottom" href="@url" target=_blank>Preview</a>
                                    
                                    @{
                                        // Don't show WYSIWYG for schema editors
                                        if (!hasSchema)
                                        {
                                            <a class="button small tabletMarginBottom" href="@Url.Action("EditContentBasic", "Admin", new { id = @page.ContentPageId })">WYSIWYG Edit</a>        
                                        }
                                    }
                                    
                                    <a class="button small" href="@codeEditUrl">Code Edit { }</a>
                                </td>
                            </tr>
					    }
                    }
                </tbody>
            </table>
        </div>
    </div>
</div>

@section Modals {
    
    @*Delete Page Modal*@
    <div id="DeleteModal" class="reveal-modal">
        <h2>Confirm Delete.</h2>
        <p class="lead">Are you sure you want to delete this page?</p>

        <p><span id="popTitle"></span>will be <em>permanently</em> deleted.</p>
        
        <div class="confirmCancelContainer">
            <a id="ConfirmContentDelete" class="right button confirmButton confirmModalButton">Confirm</a>
            <a class="right button secondary" onclick="$('#DeleteModal').trigger('reveal:close');">Cancel</a>    
        </div>

        <a class="close-reveal-modal">&#215;</a>
    </div>
}
@section Scripts {
    @{
        // Only load if there is a good reason to
        if (Model.Pages.Count > 0)
        {
            <script src="/Areas/Admin/Scripts/jquery/plugins/jquery.dataTables.min.js"></script>

            <script>
                $(document).ready(function () {
                    $("table.manageTable").dataTable({
                        "iDisplayLength": 25,
                        "aoColumnDefs": [
                            { "bSortable": false, "aTargets": ["actions"] } // No Sorting on actions
                        ],
                        "aaSorting": [[1, "desc"]] // Sort by Created Date on page load
                    });
                });
            </script>
        }
    }
}